-
Notifications
You must be signed in to change notification settings - Fork 15k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: use powerMonitor.on() only after app is ready #21927
fix: use powerMonitor.on() only after app is ready #21927
Conversation
powerMonitor can't be used until the app is ready; however, on Linux, powerMonitor.on() was called as soon as lib/browser/api/power-monitor.ts was loaded. This patch takes @vladimiry's suggestion of wrapping that in an app.on('ready') handler to prevent powerMonitor.on() from being called prematurely. Fixes #21716
Fix the previous commit's app-is-ready handler by checking to see if app is already ready when power-monitor.ts is loaded.
@zcbenz's suggestion of app.whenReady() takes care of this 🎉 |
Release Notes Persisted
|
I have automatically backported this PR to "7-1-x", please check out #21941 |
I have automatically backported this PR to "8-x-y", please check out #21942 |
Description of Change
powerMonitor can't be used until the app is ready; however, on Linux,
powerMonitor.on()
was called as soon as lib/browser/api/power-monitor.ts was loaded.This patch takes @vladimiry's suggestion of wrapping the calls in an app.on('ready') handler to prevent
powerMonitor.on()
from being called prematurely. It also adds an app.isReady() test in case powerMonitor is imported after the app is ready.Note about the caveat described there about possible sequencing errors from the lazy loading — I don't think this is an issue, because
powerMonitor.on()
can't be called by user code before the app is ready, and power-monitor.ts' on-ready-handler is registered as soon as power-monitor.ts is loaded. I'd welcome a second opinion on that though.Fixes #21716.
Checklist
npm test
passesRelease Notes
Notes: Fixed error thrown when importing powerMonitor on Linux before app's 'ready' event.